package com.nd.qa.shareplate.service.impl;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.nd.qa.shareplate.IDao.ModuleMapper;
import com.nd.qa.shareplate.common.CPResultCode;
import com.nd.qa.shareplate.model.Module;
import com.nd.qa.shareplate.service.ModuleService;

@Service("com.nd.qa.shareplate.service.ModuleService")
public class ModuleServiceImpl implements ModuleService{

	@Autowired
	private ModuleMapper moduleDao;
	
	@Override
	public HashMap<String, Object> insertModule(Module module) throws Exception{
		 moduleDao.insertModule(module);
		HashMap<String, Object> returnMap = new HashMap<String,Object>();
		returnMap.put("code", CPResultCode.CP0000);
		returnMap.put("moduleId", module.getModuleId());
		System.out.println("moduleId:"+module.getModuleId());
		return returnMap;
	}

	@Override
	public HashMap<String, Object> updateModuleById(Module module) throws Exception{
		// TODO Auto-generated method stub
		moduleDao.updateModuleById(module);
		HashMap<String, Object> resultMap = new HashMap<String,Object>();
		resultMap.put("code", CPResultCode.CP0000);
		resultMap.put("message", "修改模块成功");
		return resultMap;
	}

	@Override
	public List<HashMap<String, Object>> getProjectModule(Module module) throws Exception{
		List<HashMap<String, Object>> moduleList = moduleDao.getProjectModule(module);
		return moduleList;
	}

	@Override
	public HashMap<String, Object> deleteModuleById(Module module) throws Exception{
		
		moduleDao.deleteModuleById(module);
		HashMap<String, Object> returnMap = new HashMap<String,Object>();
		returnMap.put("code", CPResultCode.CP0000);
		return returnMap;
	}

	@Override
	public Module queryModuleById(int moduleId) throws Exception {
		// TODO Auto-generated method stub
		return moduleDao.queryModuleById(moduleId);
	}

	@Override
	public List<Module> queryModulesByProjectId(Module module) throws Exception {
		List<Module> modules  = moduleDao.queryModulesByProjectId(module);
		return modules;
	}

	@Override
	public Module queryModuleByParams(Module module) throws Exception {
		
		return moduleDao.queryModuleByParams(module);
	}

}
